package com.yjc.rabbitMQ.seven;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.yjc.rabbitMQ.utils.RabbitMQUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author shkstart
 * @create 2022-08-02 9:10
 */
public class EmitLogsTopic {
    private final static String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        System.out.println("EmitLogsTopic发送消息中......");

        Channel channel = RabbitMQUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

//        quick.orange.rabbit 被队列 Q1Q2 接收到
//        lazy.orange.elephant 被队列 Q1Q2 接收到
//        quick.orange.fox 被队列 Q1 接收到
//        lazy.brown.fox 被队列 Q2 接收到
//        lazy.pink.rabbit 虽然满足两个绑定但只被队列 Q2 接收一次
//        quick.brown.fox 不匹配任何绑定不会被任何队列接收到会被丢弃
//        quick.orange.male.rabbit 是四个单词不匹配任何绑定会被丢弃
//        lazy.orange.male.rabbit 是四个单词但匹配 Q2

        Map<String, String> resMap = new HashMap<>();
        resMap.put("quick.orange.rabbit", "被队列 Q1Q2 接收到");
        resMap.put("lazy.orange.elephant", "被队列 Q1Q2 接收到");
        resMap.put("quick.orange.fox", "被队列 Q1 接收到");
        resMap.put("lazy.brown.fox", "被队列 Q2 接收到");
        resMap.put("lazy.pink.rabbit ", "虽然满足两个绑定但只被队列 Q2 接收一次");
        resMap.put("quick.brown.fox", "不匹配任何绑定不会被任何队列接收到会被丢弃");
        resMap.put("quick.orange.male.rabbit", "是四个单词不匹配任何绑定会被丢弃");
        resMap.put("lazy.orange.male.rabbit", "是四个单词但匹配 Q2");

        for (Map.Entry<String, String> entry : resMap.entrySet()) {
            String routingKey = entry.getKey();
            String value = entry.getValue();
            channel.basicPublish(EXCHANGE_NAME, routingKey, null, value.getBytes("UTF-8"));
        }
    }
}
